<?php
/**
 * The html template file of index method of blog module of ZenTaoPHP.
 *
 * The author disclaims copyright to this source code.  In place of
 * a legal notice, here is a blessing:
 * 
 *  May you do good and not evil.
 *  May you find forgiveness for yourself and forgive others.
 *  May you share freely, never taking more than you give.
 */
?>
<?php include '../../common/view/header.html.php';?>
<div id="sidebar">
<div class="accordion open">
<a href=""  class="accordion-toggle">系统配置<i class="slider_arrow"></i></a>
<div class="accordion-body">
<ul>
<li class="active"><?php echo html::a($this->createLink($menuModule,'userconf'), '用户管理');?></li>
<li><?php echo html::a($this->createLink($menuModule,'myinfo'), '我的信息');?></li>
</div>
</div>
</div>
 <div id="main" class="alarm_mynews">
    <div class="main_title">系统配置<span class="level_divide">&gt; &gt;</span>用户管理</div>
    <div class="main_body" style="margin-top:8px;">
        <table class="table">
            <thead>
                <tr>
                    <td width="50px">userID</td>
                    <td>用户名</td>
                    <td>状态</td>
                    <td width="250px;" align="center">操作</td>
                </tr>
            </thead>
            <tbody>
             <?php foreach($user_info_list as $item):?>
              <tr>
                <td><?php echo $item->userid;?></td>
                <td><?php echo $item->username;?></td>
                <td><?php 
				    if($item->status==1){
					  echo '<span style="color:#0F3; font-weight:bold;">开启</span>';
					}else{
					  echo '<span style="color:#F00; font-weight:bold;">禁用</span>';
					}
					?></td>
                <td align="center">
                    <a href="javascript:void(0)" onClick="reset_pwd(<?php echo $item->userid;?>)">初始化密码</a>
                      &nbsp;&nbsp;
                  <?php if($item->userid!=1){?>
				      <a href="javascript:void(0)" onClick="del_user(<?php echo $item->userid;?>)">删除用户</a>
                      &nbsp;&nbsp;
						<?php
                           if($item->status==1){
                        ?>
                            <a href="javascript:void(0)" onClick="change_user_status(<?php echo $item->userid;?>,0)">禁用帐号</a>
                        <?php
                          }else{
                        ?>
                            <a href="javascript:void(0)" onClick="change_user_status(<?php echo $item->userid;?>,1)">开启帐号</a>
                        <?php
                          }
                        ?>
                  <?php }?>
                </td>
              </tr>  
              <?php endforeach;?>  
            </tbody>
        </table>
            <div>
               <div class="control-group" style="margin-top:10px; float:left">
                <label class="control-label" for=""></label>
                    <div class="controls">
                        <input type="button" class="btn btn-primary" value="添加用户" onClick="add_user()" />
                    </div>
               </div>
               
                 <div class="pages">
                <?php 
                   // echo html::a(inlink('create'), $lang->blog->add, '', "class='btn btn-primary'");
                    $pager->show('right', 'full');
               ?>
                </div>
            </div>
         </div>
    </div>
<?php include '../../common/view/footer.html.php';?>
<script src="<?php echo $jsRoot?>iDialog/jquery.iDialog.js" dialog-theme="default"></script>
<script type="text/javascript">
    //初始化密码为123456
    function reset_pwd(userid){
	   $.dialog({
			lock:true,
			width:300,
			title:'初始化用户密码',
			content:'把当前用户密码初始化为;123456',
			btn: {                      //可以任意定义按钮个数
			  ok: {                     //按钮的key值，下次可用个btn方法从新设置
				val: '修改',            //按钮显示的文本
				type: 'green',         //样式可选参数green, blue, red, yellow .默认白色。
				//disabled: true,       //是否可操作
				click: function(btn) {
				  $.post("index.php?m=sysmanage&f=reset_pwd",{userid:userid},
					function(data){
						if(data=='success'){
							tipInfo('修改成功');
						}else{
						   tipInfo('修改失败');
						}
					});
				}
			  },
			  cancle: {
				val: '取消'
			  }
			}
		 });
	}
	//删除用户
	   function del_user(userid){
	      $.dialog({
			width:300,
			lock:true,
			title:'提示信息',
			content:'确定要删除该用户吗？',
			btn: {                      
			  ok: {                     
				val: '确定',            
				type: 'green',  
				click: function(btn) {
				    $.post("index.php?m=sysmanage&f=del_user_info",{userid:userid},
						function(data){
							if(data=='success'){
							   tipInfo('删除成功');
							   location.reload();
							}else{
							   tipInfo('删除失败');
							}
						});
				}
			  },
			  cancle: {                //第四个按钮
				val: '取消'
			  }
			}
		  });
	   }
	   
	  function change_user_status(userid,status){
	     $.post("index.php?m=sysmanage&f=change_user_status",{userid:userid,status:status},
			function(data){
				if(data=='success'){
				   tipInfo('修改成功');
				   location.reload();
				}else{
				   tipInfo('修改失败');
				}
			});
	  }
     /**
		添加用户
		*/
		function add_user(){
			$.dialog({
				lock:true,
				width:560,
				height:250,
				title:'添加用户',
				content:'<div style="height:150px">Loading……</div>',
				btn: {                      //可以任意定义按钮个数
				  ok: {                     //按钮的key值，下次可用个btn方法从新设置
					val: '添加',            //按钮显示的文本
					type: 'green',         //样式可选参数green, blue, red, yellow .默认白色。
					//disabled: true,       //是否可操作
					click: function(btn) {
					  $.post("index.php?m=sysmanage&f=done_add_user",$("#add_user_form").serialize(),
						function(data){
							if(data=='success'){
								tipInfo('添加成功');
								location.reload();
							}else{
							   tipInfo('添加失败');
							}
						});
					}
				  },
				  cancle: {
					val: '取消'
				  }
				},
			 init:function(){
			    var that=this;
				 $.post("index.php?m=sysmanage&f=add_user",
					function(data){
					    that.$content.html(data);
				    });
			 }
			 });
	   }
</script>
